<template>
	<div class="main">
		<!-- alipay:支付宝; wxpay:微信; appleiap:苹果内付 -->
		<el-button @click="pay('wxpay')">微信</el-button>
		<el-button @click="pay('alipay')">支付宝</el-button>
	</div>
</template>
<script>
export default {
	data () {
		return {
			// 当前支付通道对象
			payType:"",
			// 测试数据，微信商品demo数据
			payGoods:{
				appid:"wxc8e7c8d19ab57b36",
				noncestr:"umGwjnFvypRfOFSR",
				package:"Sign=WXPay",
				partnerid:"1514929731",
				prepayid:"wx20101048460092a123dec0071514355800",
				sign:"0EA30CC655486B7C66C0C975D3E6CC9F",
				timestamp:1576808015,
			},
			
			// 测试数据，支付宝商品demo数据
			// payGoods:"alipay_sdk=alipay-sdk-java-3.3.87.ALL&app_id=2018102461817428&biz_content=%7B%22body%22%3A%22%E4%B8%8B%E5%8D%95%E9%A2%84%E4%BB%98%E6%AC%BE%22%2C%22out_trade_no%22%3A%222019122010273711857467559%22%2C%22passback_params%22%3A%22%257B%2522amount%2522%253A%252218.00%2522%252C%2522bUserUid%2522%253A%25220fd16bc91681499799573c9ed3e2961c%2522%252C%2522body%2522%253A%2522%25E4%25B8%258B%25E5%258D%2595%25E9%25A2%2584%25E4%25BB%2598%25E6%25AC%25BE%2522%252C%2522orderUid%2522%253A%25228891b9ff0803419b80a8235709b6cd38%2522%252C%2522outTradeNo%2522%253A%25222019122010273711857467559%2522%252C%2522payType%2522%253A1%252C%2522subject%2522%253A%2522123123%2522%252C%2522type%2522%253A1%252C%2522userUid%2522%253A%2522629a8b00d027454d94684a07748e0067%2522%257D%22%2C%22product_code%22%3A%22QUICK_MSECURITY_PAY%22%2C%22subject%22%3A%22123123%22%2C%22timeout_express%22%3A%2230m%22%2C%22total_amount%22%3A%2218.00%22%7D&charset=UTF-8&format=json&method=alipay.trade.app.pay&notify_url=http%3A%2F%2Ftuxiaozhu.utools.club%2Ftuxiaozhu%2Falipay%2Fnotify&sign=c6CRLMEohap4oJZEKEdLHyAjQ24Gkx61BUbbF%2BqbnGNWbz2xF%2FITcpwwoMyKJsp2%2FDoI8nn4pef%2F3yI2NUSbSOkeSuUSy%2FVxbOkN7uwP%2FiG0nXNTkxLeMsaELb5yJEmkWgiBpPbTmEGY%2BwCmek6Q1BL5wKWXLjWLpCFti1cY3YpYSDE92%2BgN3w2ZbNEHkC6f0LQWSB9SirwcuLMMBzYML%2BfWFZKMC0kTJjOlNmXwh6ZCbCmHo6n%2BJx13v18k6vyx1TPbpk8%2FbdPr5d1P9fLbuy0zohuM3tZMFEMqMGHJ6RZqQo9cFh2p3yfIm4q%2F%2F4dqH7IkZujC0rBVEuq9gwou9Q%3D%3D&sign_type=RSA2&timestamp=2019-12-20+10%3A27%3A38&version=1.0"
		}
	},
	methods:{
		pay:function(type){
			if(plus){
				// 获取当前设备支持的支付
				plus.payment.getChannels(s=>{
					// 查找微信（支付宝）
					this.payType = s.find(e=>e.id == type); 
					
					// 如果可以支付
					if(this.payType.serviceReady){
						// 请求支付操作（支付通道，订单信息，成功回调，失败回调）
						plus.payment.request(this.payType,this.payGoods,()=>{
							
						},error=>{
							plus.nativeUI.toast(error.message);
						});
					}
					else{
						if(type == 'wxpay'){
							plus.nativeUI.toast('未安装微信');
						}
						else{
							plus.nativeUI.toast('未安装支付宝');
						}
					}
				})
			}
			else{
				alert('请在APP上支付');
			}
		}
	},
	mounted(){
	
	},
	created(){

	}
}
</script>
<style lang="scss" scoped>
@import '@/style/base/border.scss';

	
</style>
